from django.contrib import admin
from .models import ChatSession, ChatMessage

@admin.register(ChatSession)
class ChatSessionAdmin(admin.ModelAdmin):
    list_display = ('session_id', 'user_id', 'start_time', 'last_activity', 'is_active')
    list_filter = ('is_active',)
    search_fields = ('session_id', 'user_id')
    date_hierarchy = 'start_time'

@admin.register(ChatMessage)
class ChatMessageAdmin(admin.ModelAdmin):
    list_display = ('message_id', 'get_session_id', 'role', 'get_content', 'timestamp')
    list_filter = ('role',)
    search_fields = ('content',)
    date_hierarchy = 'timestamp'
    
    def get_session_id(self, obj):
        return obj.session_id.session_id
    get_session_id.short_description = '会话ID'
    
    def get_content(self, obj):
        return obj.content[:50] + '...' if len(obj.content) > 50 else obj.content
    get_content.short_description = '消息内容'
